import {useRef,useEffect,useCallback} from 'react'
export  function useMountedState() {
    const mountedRef = useRef(false)
    const get=useCallback(()=>{//如果子组件使用了memo，那么就能实现缓存
        return mountedRef.current
    },[])
    useEffect(()=>{
        mountedRef.current = true//组件挂载完毕
        return ()=>{//组件卸载
            mountedRef.current = false
        }
    },[])
    return get
}
